<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form_timetable" class="layui-form-item wx-search">
            <div class="layui-inline">
                <label class="layui-form-label">学年</label>
                <div class="layui-input-block">
                    <input type="hidden" name="squadCode" value="<%=squadCode%>">
                    <select name="year" class="layui-input">
                        <option value="2020">2020</option>
                        <option value="2021">2021</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">学期</label>
                <div class="layui-input-block">
                    <select name="term" class="layui-input">
                        <option value="1">1</option>
                        <option value="2">2</option>
                    </select>
                </div>
            </div>
            <button class="layui-btn" id="search_timetable">搜索</button>
        </div>
        <table id="list_table_timetable" class="layui-hide" lay-filter="mainList_timetable"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo_timetable_timetable">
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="add">新增</button>
        <!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
        <!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
        <!--        <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>-->
    </div>
</script>
<script type="text/html" id="barDemo_timetable">
    <a class="font-primary" lay-event="fabu">发布</a>
    <a class="font-primary" lay-event="detail">查看</a>
    <a class="font-primary" lay-event="update">编辑</a>
    <a class="font-primary" lay-event="del">删除</a>
</script>

<script>
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;
        var originData = JSON.parse($('<div>').html('<%=$data%>').text());
        var _squadCoe = originData.squadCode || "0";
        var tableObj_timetable = table.render({
            elem: '#list_table_timetable',
            url: context + '/api/eduSchoolTimetable/list',
            where: util.getFormData('list_form_timetable'),
            //开启头部工具栏，并为其绑定左侧模板，
            toolbar: '#toolbarDemo_timetable_timetable',
            defaultToolbar: ['filter', 'exports', 'print', {}],
            request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            align: 'center'
            , cols: [[ //表头
                // {type: 'checkbox', fixed: 'left'},
                {field: 'timetable_id', title: 'ID', align: 'center'},
                {field: 'courseNum', title: '课程编号', align: 'center'},
                {field: 'title', title: '课程名称', align: 'center'},
                {field: 'must', title: '必修', align: 'center'},
                {field: 'week', title: '周几', align: 'center'},
                {field: 'sort', title: '第几节课', align: 'center'},
                {field: 'plan_id', title: '教学计划', align: 'center'},
                {field: 'teacher_id', title: '教师ID', align: 'center'},
                {field: 'squadCode', title: '班级', align: 'center'},
                {title: '操作', align: 'center', width: 260 ,toolbar: '#barDemo_timetable'}
            ]]
            , page: true
        });
        //头工具栏事件
        table.on('toolbar(mainList_timetable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            //测试数据
            var testData = {title: '动画基础',year: 2020, term: 1, courseNum: '202001', plan_id: 483, week: 1, sort: 1, teacher_id: 1, weekTime: 1,
                allTime: 10, must: 1, score: 2, address: "多媒体教室一", remark: "自备纸笔"};
            $.extend(testData, originData);
            switch (obj.event) {
                case 'add':
                    showDialog({
                        title: '新建'
                        , template: context + '/views/school/timetable/template/add.html'
                        , tableObj: tableObj_timetable
                        , saveUrl: context + '/api/eduSchoolTimetable/add'
                        , htmlData: testData
                        , width: 1000
                        , height: 550
                        , type: "post"
                        , dataType: 'json'
                    });
                    break;
            }
        });

        // 检索
        $("#search_timetable").click(function () {
            reloadTable(tableObj_timetable, 'list_form_timetable');
        });
        //表格内部操作按钮监听
        table.on('tool(mainList_timetable)', function (obj) { //注：tool是工具条事件名，mainList_timetable是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值

            if (layEvent === 'update') {
                showDialog({
                    title: '编辑 - ' + data.week + " - " + data.sort
                    , template: context + '/views/school/timetable/template/add.html'
                    , saveUrl: context + '/api/eduSchoolTimetable/update'
                    , tableObj: tableObj_timetable
                    , htmlData: data
                    , type: "patch"
                    , dataType: 'json'
                })
            } else if (layEvent === 'detail') {
                showDialog({
                    title: '查看 - ' + data.week + " - " + data.sort
                    , type: 'get'
                    , template: context + '/views/school/timetable/template/add.html'
                    , htmlData: data
                })
            }else if (layEvent === 'del') {
                confirmDel(context + "/api/eduSchoolTimetable/del/" + data.timetable_id, tableObj_timetable);
            }else if (layEvent === 'fabu') {
                showDialog({
                    title: '发布 - ' + data.week + " - " + data.sort
                    , template: context + '/views/school/timetable/template/publish.html'
                    , saveUrl: context + '/api/eduSchoolTimetable/updatePublish'
                    , tableObj: tableObj_timetable
                    , htmlData: data
                    , type: "patch"
                    , dataType: 'json'
                })
            }
        }
        );
    });
</script>
<style>
    img.fans-portrait {
        width: 50px;
        height: 50px;
    }

    .fsh-rightPanel .layui-table-body .layui-table-cell {
        height: 50px;
        line-height: 50px;
    }
</style>